package com.star.carservice.client.fragment;

import java.nio.Buffer;

import javax.security.auth.PrivateCredentialPermission;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

import com.baidu.platform.comapi.map.m;
import com.star.carservice.R;
import com.star.carservice.client.activity.SelectCarActivity;
import com.star.carservice.client.fragment.base.BaseFragment;
import com.star.carserviceapi.domain.CarFeatureInfo;
import com.star.carserviceapi.domain.request.QryCarBrandRequest;
import com.star.carserviceapi.domain.result.QryCarBrandResult;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ListView;

public class AddCarFragment extends BaseFragment {

	private final static String TAG = AddCarFragment.class.getSimpleName();

	private CarFeatureInfo mCarFeatureInfo = null;

	@Override
	public String getLogTag() {
		return TAG;
	}

	@InjectView(R.id.input_select_brand)
	EditText input_select_brand;

	@InjectView(R.id.input_select_car_type)
	EditText input_select_car_type;
	
	@InjectView(R.id.input_distance)
	EditText input_distance;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);

		if (CacheViewIsNull()) {
			mCacheView = inflater.inflate(R.layout.frag_add_car, container,
					false);

			ButterKnife.inject(this, mCacheView);
		}

		removeCacheView();

		return mCacheView;
	}

	@OnClick(R.id.input_select_brand)
	public void onSelectBrand(View view) {

		startActivityForResult(new Intent(getActivity(),
				SelectCarActivity.class), 100);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {

		if (requestCode == 100 && resultCode == Activity.RESULT_OK) {
			mCarFeatureInfo = (CarFeatureInfo) data
					.getSerializableExtra(SelectCarActivity.KEY_CAR);

			input_select_brand.setText(mCarFeatureInfo.getDisplayName());
		}

		super.onActivityResult(requestCode, resultCode, data);
	}

	@OnClick(R.id.input_select_car_type)
	public void onSelectCarType(View v) {

		final String[] carTypes = new String[] { "小型汽车" };

		new AlertDialog.Builder(getActivity())

		.setTitle("请选择号牌类型").setItems(carTypes, new OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				input_select_car_type.setText(carTypes[which]);
			}
		}).show();
	}
	
	@OnClick(R.id.btn_add_car)
	public void onAddCar(View v){
		
	}

}
